﻿@using VMdai.Commons
@using VMdai.Models.RequestModels
@inherits ViewPage<VMdai.Models.ResponseModels.LoanRepaymentResponse>
              @Html.Partial("_navbar")
<div class="next_head">
    <div class="wrap">借款列表进行还款</div>
</div>

<div class="content_nav">
    <div class="tag_nav wrap">
        <div class="col-xs-12 pd-n">
            <table class="table">
                <thead>
                    <tr>
                        <th colspan="6"><a href="/project/index/@Model.ProjectId" target="_blank">@Model.ProjectListDetail.Title</a></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td width="100"><span class="tit-p">借款金额：</span></td>
                        <td><span class="alt-p">@Model.ProjectListDetail.Amount.ToString("C2")</span></td>
                        <td width="100"><span class="tit-p">年利率：</span></td>
                        <td><span class="alt-p">@Model.ProjectListDetail.Rate%</span></td>
                        <td width="100"><span class="tit-p">期限：</span></td>
                        <td><span class="alt-p">@Model.ProjectListDetail.LoanPeriod @(Model.ProjectListDetail.IsDay == 0 ? "个月" : "天")</span></td>
                    </tr>
                    <tr>
                        <td><span class="tit-p">应付本息：</span></td>
                        <td><span class="alt-p">@((Model.ProjectRepaymentTotal.RepayAmount + Model.ProjectRepaymentTotal.OwingAmount).Value.ToString("C2"))</span></td>
                        <td><span class="tit-p">已付本息：</span></td>
                        <td><span class="alt-p">@Model.ProjectRepaymentTotal.RepayAmount.Value.ToString("C2")</span></td>
                        <td><span class="tit-p">待还本息：</span></td>
                        <td><span class="alt-p">@Model.ProjectRepaymentTotal.OwingAmount.Value.ToString("C2")</span></td>
                    </tr>
                </tbody>
            </table>
            <div id="item_back">
                <table class="table  table-hover table-bordered">
                    <thead>
                        <tr>
                            <th>还款日</th>
                            <th>未还金额/已还金额</th>
                            <th>未还本金</th>
                            <th>未还利息</th>
                            <th>逾期利息</th>
                            <th>状态</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.ProjectRepayments)
                        {
                            <tr>
                                <td>@item.DueDate.Value.ToString("yyyy-MM-dd")</td>
                                <td>@item.OwingAmount.Value.ToString("C2")/@item.RepayAmount.Value.ToString("C2")</td>
                                <td>@item.OwingPrincipal.Value.ToString("C2")</td>
                                <td>@item.OwingInterest.Value.ToString("C2")</td>
                                <td>@((item.OwingDun + item.OwingOverdue).Value.ToString("C2"))</td>
                                <td>@Html.Raw(HelperUtils.GetProjectReceivableStatusHtml(item.StatusId ?? 0, item.DueDate ?? DateTime.MinValue))</td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
            @if (Model.ProjectRepayments.Count > 0 && Model.ProjectRepaymentTotal.OwingAmount > 0)
            {
                <form class="form-horizontal" role="form" action="/account/repayment/@Model.ProjectId" method="POST">
                    <div class="form-group">
                        <label class="col-xs-2 control-label tit-p">您的账户余额：</label>
                        <div class="col-xs-10">
                            <p class="alt-p form-control-static"><strong>@Model.Balance.ToString("C2")</strong></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="inputPassword3" class="col-xs-2 control-label tit-p">选择还款状态：</label>
                        <div class="col-xs-10">
                            <div class="radio_nav on">
                                <div class="radio">
                                    <label>
                                        <input type="radio" name="RepaymentType" value="1" checked>
                                        按期还款
                                    </label>
                                    <div class="backcont">
                                        @{ int n = Model.ProjectRepaymentTotal.CurrentPeriod.Value; }
                                        <span class="alt-p">@Model.ProjectRepayments[n].OwingAmount.Value.ToString("C2")</span>&nbsp;&nbsp;<span class="tit-p">@Model.ProjectRepayments[n].DueDate</span>
                                    </div>
                                </div>
                            </div>
                            @if (!Model.IsPrepayment && Model.Balance >= Model.PrepaymentAmount && DateTime.Now > Model.ProjectRepayments[n].DueDate)
                            {
                                decimal? interest = Model.ProjectRepaymentTotal.OwingAmount - Model.PrepaymentAmount;
                                <div class="radio_nav">
                                    <div class="radio">
                                        <label>
                                            <input type="radio" name="RepaymentType" value="2" checked>
                                            提前还清所有欠款
                                        </label>
                                        <div class="backcont">
                                            <span class="alt-p">@Model.PrepaymentAmount.ToString("C2")</span><span class="tit-p">&nbsp;（提前还款，可以少支付 </span><span class="alt-p">利息 @interest.Value.ToString("C2")</span><span class="tit-p">）</span>
                                        </div>
                                    </div>
                                </div>
                            }
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-offset-2 col-sx-10">
                            @if (Model.Balance < Model.ProjectRepayments[n].OwingAmount.Value)
                            {
                                <span class="alt-p">余额不足，请先进行<a href="/recharge">充值</a></span>
                            }
                            else
                            {
                                <button type="submit" class="btn btn-primary btn-lg repaymentbtn" id="repaymentBtn">还款</button>
                            }
                        </div>
                    </div>
                </form>
            }

            @if (Model.ResponseStatus.ErrorCode == ResultCode.Success.ToString())
            { 
                <div class="alert alert-success">@Model.ResponseStatus.Message</div>
            }
            else if (Model.ResponseStatus.ErrorCode == ResultCode.Fail.ToString())
            {
                <div class="alert alert-danger">@Model.ResponseStatus.Message</div>
            }

        </div>
    </div>
</div>
<script >
    $("#10009").addClass("on");
</script>
